
/**
 *  Copyright 2011 classic-commerce
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package ca.ioniq.server.resource.impl;

import javax.inject.Inject;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;

import ca.ioniq.server.resource.BrandResource;
import ca.ioniq.server.service.InventoryService;
import ca.ioniq.server.service.exception.InventoryException;
import ca.ioniq.shared.entity.Brand;

public class BrandResourceImpl implements BrandResource {

    private InventoryService inventoryService;

    @Inject
    public BrandResourceImpl(InventoryService inventoryService) {
        this.inventoryService = inventoryService;
    }

	public Brand put(Brand brand) {
		return inventoryService.addBrand(brand);
	}

	public void update(Brand brand) {
		try {
			inventoryService.updateBrand(brand, brand.getId());
		} catch (InventoryException e) {
			throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
		}	}

	public void delete(Long id) {
		 try {
				inventoryService.removeBrand(id);
			} catch (InventoryException e) {
				throw new WebApplicationException(e, Response.Status.BAD_REQUEST);
			}		}

}
